/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vamprest.api;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import vamprest.Link;

/**
 *
 * @author sav
 */
@Stateless
@Path("link")
public class LinkFacadeREST extends AbstractFacade<Link> {
    @PersistenceContext(unitName = "vamprestPU")
    private EntityManager em;

    public LinkFacadeREST() {
        super(Link.class);
    }

    @POST
    @Path("{databaseLogin}/{databasePassword}/{userEmail}/{userPassword}")
    @Consumes({"application/xml", "application/json"})
    public void create(Link entity, @PathParam("databaseLogin") String databaseLogin, @PathParam("databasePassword") String databasePassword, @PathParam("userEmail") String userEmail, @PathParam("userPassword") String userPassword) {
        try {
            String[] identification = new String[] {databaseLogin, databasePassword, userEmail, userPassword};
            super.create(entity, identification);
        } catch (Exception e) {
        }
    }

    @GET
    @Path("insertsql/{databaseLogin}/{databasePassword}/{userEmail}/{userPassword}/{statment}")
    @Consumes({"application/xml", "application/json"})
    @Produces({"application/xml", "application/json"})
    public String create(@PathParam("databaseLogin") String databaseLogin, @PathParam("databasePassword") String databasePassword, @PathParam("statment") String statment, @PathParam("userEmail") String userEmail, @PathParam("userPassword") String userPassword) {
        try {
            String[] identification = new String[] {databaseLogin, databasePassword, userEmail, userPassword};
            return new Integer(super.queryExecuteStatement(identification, statment, false)).toString();
        } catch (Exception e) {
            return "-1";
        }
    }

    @PUT
    @Path("{databaseLogin}/{databasePassword}/{userEmail}/{userPassword}")
    @Consumes({"application/xml", "application/json"})
    public void edit(Link entity, @PathParam("databaseLogin") String databaseLogin, @PathParam("databasePassword") String databasePassword, @PathParam("userEmail") String userEmail, @PathParam("userPassword") String userPassword) {
        try {
            String[] identification = new String[] {databaseLogin, databasePassword, userEmail, userPassword};
            super.edit(entity, identification);
        } catch (Exception e) {
        }
    }

    @DELETE
    @Path("{databaseLogin}/{databasePassword}/{userEmail}/{userPassword}/{id}")
    public void remove(@PathParam("id") Long id, @PathParam("databaseLogin") String databaseLogin, @PathParam("databasePassword") String databasePassword, @PathParam("userEmail") String userEmail, @PathParam("userPassword") String userPassword) {
        try {
            String[] identification = new String[] {databaseLogin, databasePassword, userEmail, userPassword};
            super.remove(super.find(id, identification), identification);
        } catch (Exception e) {
        }
    }

    @GET
    @Path("{databaseLogin}/{databasePassword}/{userEmail}/{userPassword}/{id}")
    @Produces({"application/xml", "application/json"})
    public Link find(@PathParam("id") Long id, @PathParam("databaseLogin") String databaseLogin, @PathParam("databasePassword") String databasePassword, @PathParam("userEmail") String userEmail, @PathParam("userPassword") String userPassword) {
        try {
            String[] identification = new String[] {databaseLogin, databasePassword, userEmail, userPassword};
            return super.find(id, identification);
        } catch (Exception e) {
            return null;
        }
    }

    @GET
    @Path("{databaseLogin}/{databasePassword}/{userEmail}/{userPassword}")
    @Produces({"application/xml", "application/json"})
    public List<Link> findAll(@PathParam("databaseLogin") String databaseLogin, @PathParam("databasePassword") String databasePassword, @PathParam("userEmail") String userEmail, @PathParam("userPassword") String userPassword) {
        try {
            String[] identification = new String[] {databaseLogin, databasePassword, userEmail, userPassword};
            return super.findAll(identification);
        } catch (Exception e) {
            return null;
        }
    }

    @GET
    @Path("{databaseLogin}/{databasePassword}/{userEmail}/{userPassword}/{from}/{to}")
    @Produces({"application/xml", "application/json"})
    public List<Link> findRange(@PathParam("from") Integer from, @PathParam("to") Integer to, @PathParam("databaseLogin") String databaseLogin, @PathParam("databasePassword") String databasePassword, @PathParam("userEmail") String userEmail, @PathParam("userPassword") String userPassword) {
        try {
            String[] identification = new String[] {databaseLogin, databasePassword, userEmail, userPassword};
            return super.findRange(new int[]{from, to}, identification);
        } catch (Exception e) {
            return null;
        }
    }
    @GET
    @Path("count/{databaseLogin}/{databasePassword}/{userEmail}/{userPassword}")
    @Produces("text/plain")
    public String countREST(@PathParam("databaseLogin") String databaseLogin, @PathParam("databasePassword") String databasePassword, @PathParam("userEmail") String userEmail, @PathParam("userPassword") String userPassword) {
        try {
            String[] identification = new String[] {databaseLogin, databasePassword, userEmail, userPassword};
            return String.valueOf(super.count(identification));
        } catch (Exception e) {
            return "-1";
        }
    }

    @GET
    @Path("select/{databaseLogin}/{databasePassword}/{userEmail}/{userPassword}/{selectStatement}")
    @Produces({"application/xml", "application/json"})
    public List<Link> querySelectStatement(@PathParam("databaseLogin") String databaseLogin, @PathParam("databasePassword") String databasePassword, @PathParam("userEmail") String userEmail, @PathParam("userPassword") String userPassword, @PathParam("selectStatement") String statement) {
        try {
            String[] identification = new String[] {databaseLogin, databasePassword, userEmail, userPassword};
            List<Link> lst = (List<Link>) super.querySelectStatement(identification, statement);
            return lst;
        } catch (Exception e) {
            return null;
        }
    }

    @java.lang.Override
    protected EntityManager getEntityManager() {
        return em;
    }

}
